<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		function objectCopy(obj) {
			function Fun() { };
			Fun.prototype = obj;
			return new Fun();
		}

		function inheritPrototype(child, parent) {
			let prototype = objectCopy(parent.prototype); // 创建对象
			prototype.constructor = child; // 增强对象
			child.prototype = prototype; // 赋值对象
		}

		function Parent(name) {
			this.name = name;
			this.friends = ["rose", "lily", "tom"]
		}

		Parent.prototype.sayName = function () {
			console.log(this.name);
		}

		function Child(name, age) {
			Parent.call(this, name);
			this.age = age;
		}

		inheritPrototype(Child, Parent);
		Child.prototype.sayAge = function () {
			console.log(this.age);
		}

		let child1 = new Child("yhd", 23);
		child1.sayAge(); // 23
		child1.sayName(); // yhd
		child1.friends.push("jack");
		console.log(child1.friends); // ["rose", "lily", "tom", "jack"]

		let child2 = new Child("yl", 22)
		child2.sayAge(); // 22
		child2.sayName(); // yl
		console.log(child2.friends); // ["rose", "lily", "tom"]
	</script>
</body>

</html>